<?php
// error_reporting(E_ALL);

/**
 * Context Class.
 * Singleton resource for
 * session and site information.
 *
 */

class Context
{
    protected $_user;

	function __construct() 
    {
        global $db ;

        require_once "Db.class.php";
        if( ! isset( $Db ) ) {
            $db = new Db() ;
        }
        $this->init_user();
	}

    public function Dump()
    {
        var_dump($this);
    }

	private function init_user() 
    {
        require_once "User.class.php";
        $this->_user = new User();
    }

    public function User()
    {
        return $this->_user;
    }

    public function IsLoggedIn()
    {
        // wp function
        return is_user_logged_in();
    }

    public function SlugCategory( $slug )
    {
        require_once "Category.class.php";
        return new SlugCategory( $slug );
    }

    public function GetPageForID( $id )
    {
        require_once "Page.class.php";
        return new Page( $id );
    }
/*
	public function LogEvent( $projectid = null, 
                              $pagecode = null,
                              $version = 0,
                              $taskcode = null,
                              $eventcode = null ) 
    {
		global $Db;

        $eventcode  = QuoteOrNull($eventcode);
        $username   = QuoteOrNull($this->_user->UserName()) ;
        $projectid  = QuoteOrNull($projectid) ;
        $pagecode   = QuoteOrNull($pagecode) ;
        $taskcode   = QuoteOrNull($taskcode) ;
        $version    = "$version" ;

		$sql = "INSERT INTO eventlog
                (
                    eventcode,
                    createtime,
                    username,
                    projectid,
                    pagecode,
                    taskcode,
                    versionnumber 
                ) VALUES (
                    $eventcode,
                    UNIX_TIMESTAMP(),
                    $username,
                    $projectid,
                    $pagecode,
                    $taskcode,
                    $version
                )";
		$Db->SqlExecute($sql);
	}
*/
}
?>
